/**
 * 领券中心
 */
import 'package:cbec_app/components/base/base_page.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/components/common/coupon_item.dart';
import 'package:cbec_app/components/base/base_nav_bar.dart';
import 'package:cbec_app/components/common/not_found.dart';
import 'package:cbec_app/pages/my/controller/coupon_ctr.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class CouponCenter extends StatelessWidget {
  CouponController CouponCtr = Get.find<CouponController>();

  CouponCenter({super.key});

  @override
  Widget build(BuildContext context) {
    return BasePage(
      title: "领券中心",
      iconType: IconType.back,
      isShowPadding: true,
      paddingTop: 10.h,
      children: [
        SizedBox(
          height: 620.h,
          child:  Obx(() => CouponCtr.couponList!.isNotEmpty? Tools.getPullRefresh(
            enablePullDown: true,
            enablePullUp: CouponCtr.hasNextPage,
            refreshController: CouponCtr.baseRefreshCtr,
            onRefresh: CouponCtr.onPageRefresh,
            onLoading: CouponCtr.onPageLoading,
            child: ListView.builder(
              itemCount: CouponCtr.couponList!.length,
              itemBuilder: (context, index) {
                final item = CouponCtr.couponList?[index];
                return CouponItem(
                  item: item!,
                  status: 4,
                  onClick: (){
                    CouponCtr.receiveCoupon(item.couponId.toString());
                  },
                );
              },
            ),
          ):const NotFound())
        ),

        Positioned(
            key: GlobalKey(debugLabel: 'Positioned'),
            bottom: 1,
            child: Container(
              padding: EdgeInsets.fromLTRB(18.w, 10.w, 18.w, 10.w),
              width: 375.w,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    width: 240.w,
                    height: 38.h,
                    padding: EdgeInsets.only(left: 10.w,top: 10.w),
                    decoration: border_radis(Colors.white,radiusValue: 5.w),
                    child: TextFormField(
                      controller: CouponCtr.codetxtController,
                      decoration: descript("请输入兑换码",fontsize: 16),
                    ),
                  ),
                  solidButton("确认", width: 72.w,radius: 40.w, () {
                    CouponCtr.exchange();
                  })
                ],
              ),
            ))
      ],
    );
  }
}
